package io.renren.modules.medical.controller;


import io.renren.common.result.Result;
import io.renren.modules.medical.entity.DictDistrictEntity;
import io.renren.modules.medical.service.DictDistrictService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 信息模块地址选择接口
 * @author luosheng
 * @date 2023-05-05 09:39:14
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("medical/district")
public class DictDistrictController {

    private final DictDistrictService dictDistrictService;

    /**
     * 根据父编码获取到子集合
     */
    @GetMapping("/getByParent/{parent}")
    public Result<List<DictDistrictEntity>> getByParent(@PathVariable String parent){
        List<DictDistrictEntity> resultList = dictDistrictService.getByParent(parent);
        return Result.success(resultList);
    }

    /**
     * 根据省市区的code获取到名称串
     */
    @GetMapping("/getAddress")
    public Result<String> getChildrenByName(@RequestParam("province") String province,
                                                              @RequestParam("city") String city,
                                                              @RequestParam("district") String district){
        String address = dictDistrictService.getAddress(province, city, district);
        return Result.success(address);
    }
}
